package com.kfm.bootmp.util;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;

@Data
@NoArgsConstructor
public class R extends HashMap<String, Object> implements Serializable {

    public R(int code, String message){
        this.put("code", code);
        this.put("message", message);
        this.put("timestamp", System.currentTimeMillis());
    }

    public R put(String key, Object value){
        super.put(key, value);
        return this;
    }

    public static R ok(){
        return new R(200, "操作成功");
    }

    public static R ok(String message){
        return new R(200, message);
    }

    public static R ok(Object data){
        return new R(200, "操作成功").put("data", data);
    }

    public static R error(String message){
        return new R(500, message);
    }

    public static R error(int code, String message){
        return new R(code, message);
    }
}
